package objloader;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import javax.media.opengl.GL2;

@SuppressWarnings({ "unused" })
public class ObjFigure {
	// Paths of the 3D models.
	String objPathAndFile;
	String texturePathAndFile;
	String path;
	protected GLModel model1;
	
	
	

	public ObjFigure(String objFileName, String textureFileName, String path) {
		super();
		this.objPathAndFile = path + "/" + objFileName;
		this.texturePathAndFile = path + "/" +textureFileName;
		this.path = path;
	}

	public void init(GL2 gl) {

		System.out.println("ModelLoaderOBJ init() start..."); // ddd

		// / texture_manager = TextureManager.getInstance( gl, glu );
		gl.glEnable(GL2.GL_TEXTURE_2D);
		gl.glShadeModel(GL2.GL_SMOOTH);

		// here the needed textures for the race-ground are loaded
		try {
			// / texture_manager.createManagedTexture
			// / ("road", "textures/roads/road.jpg",
			// / GL.GL_TEXTURE_2D, GL.GL_RGB, GL.GL_RGB, GL.GL_LINEAR,
			// / GL.GL_LINEAR, true, true );
			// ...
		
			// Leer el *.obj
			FileInputStream r_path1 = new FileInputStream(objPathAndFile);
			BufferedReader b_read1 = new BufferedReader(new InputStreamReader(
					r_path1));
			model1 = new GLModel(b_read1, true, texturePathAndFile,path, gl);
			r_path1.close();
			b_read1.close();

		} catch (Exception e) {
			System.out.println("LOADING ERROR" + e);
		}

		System.out.println("ModelLoaderOBJ init() done"); // ddd
	}

	public void draw(GL2 gl) {

		// CAR 1 COORDINATES
		float car1_x = 0f;
		float car1_y = 0f;
		float car1_z = 0f;

		// //CAR 2 COORDINATES
		// float car2_x = 0f;
		// float car2_y = 0f;
		// float car2_z = 0f;

		float movement_angle = (float) Math.PI / 2;
		// float movement_angle2=(float)Math.PI/2;

		// it draws a race-ground
		// draw_floor(gl);

		gl.glDisable(GL2.GL_COLOR_MATERIAL);

		// *********positioning the car models*********
		// ***car 1***
		gl.glPushMatrix();

		// gl.glTranslatef(car1_x, car1_y, car1_z);
		// gl.glScalef(0.0005F, 0.0005F, 0.0005F); //TOO BIG
		// gl.glRotatef(-90.0f, 0.0F, 1.0F, 0.0F);
		// gl.glRotatef((float)Math.toDegrees(movement_angle),0.0f,1.0f,0.0f);

		// draws the model
		model1.opengldraw(gl);

		gl.glPopMatrix();

		// //***CAR2***
		// gl.glPushMatrix();

		// gl.glTranslated(car2_x, car2_y, car2_z);
		// gl.glScalef(0.0005F, 0.0005F, 0.0005F); //TOO BIG
		// gl.glRotatef(-90.0f, 0.0F, 1.0F, 0.0F);
		// gl.glRotatef((float)Math.toDegrees(movement_angle2),0.0f,1.0f,0.0f);

		// //draws the model
		// model2.opengldraw(gl);

		// gl.glPopMatrix();

	}
}
